<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('流程版本配置')"/>
    <th:block th:include="include :: jquery-smartwizard-css"/>
    <style type="text/css">
        /* 如果要让工具栏固定在页面底部,使用下面的样式,不需要的可以注释 */
        .sw > .toolbar-bottom {
            z-index: 100;
            bottom: 0px;
            left: 0;
            width: 100%;
            position: fixed;
            text-align: right;
            background: #fff;
            box-shadow: 0 -2px 6px 1px hsla(223, 8%, 83%, .5);
            border-top: 1px solid #e3e4e8;
        }

        /* 如果设置了是否自动调节高度为false,需要加滚动条 */
        .sw > .tab-content {
            overflow-x: hidden;
            overflow-y: auto;
        }

        .radiowrap {
            padding-top: 0;
        }

        .radiowrap .iradio-blue {
            top: 0;
        }
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight" style="height: 100%;overflow: hidden;">
    <div class="row" style="height: 100%;">
        <div class="col-sm-12" style="height: 100%;">
            <div class="ibox">
                <div class="ibox-title">
                    <form id="formId">
                        <input name="flowId" id="flowId" th:field="*{wflFlowversion.flowId}" type="hidden">
                        <input name="versionId" id="versionId" th:field="*{wflFlowversion.versionId}" type="hidden">
                        <input name="orderNum" id="orderNum" value="1" type="hidden">
                    </form>
                    <h5>
                        流程版本配置
                    </h5>
                </div>
                <div class="ibox-content" style="height: calc(100% - 40px);">
                    <div id="smartwizard" style="height: 100%;">
                        <ul class="nav">
                            <li class="nav-item">
                                <a class="nav-link" href="#step-1"> 第一步：流程审批节点配置 </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="#step-2"> 第二步：流程节点审批配置</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="#step-3"> 第三步：流程节点页面配置 </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="#step-4"> 第四步：节点跳过条件配置 </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="#step-5"> 第五步：流程节点逻辑配置 </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="#step-6"> 第六步：流程节点影像配置 </a>
                            </li>
                        </ul>
                        <!--流程配置第一步-->
                        <div class="tab-content" style="height: calc(100% - 60px);">
                            <div id="step-1" class="tab-pane" role="tabpanel" aria-labelledby="step-1"
                                 style="height:100%;">
                                <div>
                                    <div class="col-sm-6 select-table table-striped" style="float: left;width: 45%;">
                                        <span><b>备选节点列表</b></span>
                                        <table id="alternative-step-table"></table>
                                    </div>
                                    <div class="col-sm-6"
                                         style="display: flex;flex-direction: column;justify-content: center;width: 10%;align-items: center">

                                        <button type="button" class="btn btn-w-m btn-primary"
                                                style="margin-bottom: 10px" onclick="selectStep()">选择
                                        </button>
                                        <button type="button" class="btn btn-w-m btn-danger"
                                                style="margin-bottom: 10px" onclick="removeStep()">移除
                                        </button>


                                    </div>
                                    <div class="col-sm-6 select-table table-striped" style="float: right;width: 45%;">
                                        <span><b>已选节点列表</b></span>
                                        <table id="selected-step-table"></table>
                                    </div>

                                </div>
                            </div>
                            <!--流程配置第二步-->
                            <div id="step-2" class="tab-pane" role="tabpanel" aria-labelledby="step-2"
                                 style="height:600px;">
                                <div class="col-sm-6 select-table table-striped" style="float: left;width: 44%;">
                                    <span><b>流程步骤列表</b></span>
                                    <table id="flowstep-table2"></table>
                                </div>
                                <div class="col-sm-12 select-table table-striped" style="float: right;width: 55%;">
                                    <form class="form form-horizontal m-t" id="form-flowstep-add">
                                        <input name="stepId" id="stepId" type="hidden">
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label is-required">任务方案：</label>
                                            <div class="col-sm-4">
                                                <select name="taskMode" id="taskMode" class="form-control m-b"
                                                        th:with="type=${@dict.getType('wfl_flowstep_task_mode')}"
                                                        onchange="taskModeChange('')" required>
                                                    <option value="">请选择任务方案</option>
                                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                                            th:value="${dict.dictValue}"></option>
                                                </select>
                                            </div>
                                            <label class="col-sm-2 control-label is-required">任务定位：</label>
                                            <div class="col-sm-4">
                                                <select name="taskPosition" id="taskPosition"
                                                        class="form-control m-b"
                                                        th:with="type=${@dict.getType('wfl_flowstep_task_position')}"
                                                        required onchange="taskPositionChange('')">
                                                    <option value="">请选择任务定位</option>
                                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                                            th:value="${dict.dictValue}"></option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">审批机构：</label>
                                            <div class="col-sm-10">
                                                <div class="input-group">
                                                    <input name="taskOrgId" id="taskOrgId" type="hidden"/>
                                                    <input class="form-control" type="text" name="taskOrgName"
                                                           onclick="selectDeptTree()"
                                                           id="taskOrgName">
                                                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">任务索引：</label>
                                            <div class="col-sm-4">
                                                <select name="taskIndex" id="taskIndex"
                                                        class="form-control m-b">
                                                </select>
                                            </div>
                                            <label class="col-sm-2 control-label is-required">分配策略：</label>
                                            <div class="col-sm-4">
                                                <select name="taskPolicy" id="taskPolicy" class="form-control m-b"
                                                        th:with="type=${@dict.getType('wfl_flowstep_task_policy')}"
                                                        required onchange="taskPolicyChange()">
                                                    <option value="">请选择分配策略</option>
                                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                                            th:value="${dict.dictValue}"></option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">自定义SQL：</label>
                                            <div class="col-sm-10">
                                                <textarea name="defineSql" id="defineSql"
                                                          class="form-control"></textarea>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label is-required">过滤上步提交人：</label>
                                            <div class="col-sm-4">
                                                <select name="laststepFilter" id="laststepFilter"
                                                        class="form-control m-b"
                                                        th:with="type=${@dict.getType('workflowsts')}" required>
                                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                                            th:value="${dict.dictValue}"></option>
                                                </select>
                                            </div>
                                            <label class="col-sm-2 control-label">并发审批模式：</label>
                                            <div class="col-sm-4">
                                                <select name="approvMode" id="approvMode" class="form-control m-b"
                                                        th:with="type=${@dict.getType('wfl_flowstep_approv_mode')}"
                                                        onchange="approvModeChange()">
                                                    <option value="">请选择并发审批模式</option>
                                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                                            th:value="${dict.dictValue}"></option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">参与人数：</label>
                                            <div class="col-sm-4">
                                                <input name="approvPop" id="approvPop" class="form-control"
                                                       type="number" maxlength="2">
                                            </div>

                                            <label class="col-sm-2 control-label">通过人数：</label>
                                            <div class="col-sm-4">
                                                <input name="passPop" id="passPop" class="form-control" type="number"
                                                       maxlength="2">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label is-required">审批权限：</label>
                                            <div class="col-sm-4" id="approvPowerDiv">

                                            </div>
                                            <label class="col-sm-2 control-label is-required">审批限时(小时)：</label>
                                            <div class="col-sm-4">
                                                <input name="timeLimit" id="timeLimit" class="form-control"
                                                       type="number"
                                                       maxlength="2" required>
                                                <span class="help-block m-b-none" style="color: red"><i
                                                        class="fa fa-info-circle"></i>默认0代表不限时</span>
                                            </div>
                                        </div>
                                    </form>
                                    <div align="right">
                                        <button type="button" class="btn btn-w-m btn-primary"
                                                style="margin-bottom: 10px" onclick="saveWflApprovInfo()">保存
                                        </button>
                                    </div>

                                </div>
                            </div>
                            <!--流程配置第三步-->
                            <div id="step-3" class="tab-pane" role="tabpanel" aria-labelledby="step-3"
                                 style="height:600px;">
                                <div class="col-sm-6 select-table table-striped" style="float: left;width: 44%;">
                                    <span><b>流程步骤列表</b></span>
                                    <table id="flowstep-table3"></table>
                                </div>
                                <div class="col-sm-6 select-table table-striped" style="float: right;width: 55%;">
                                    <a class="btn btn-success" onclick="addPage()">
                                        <i class="fa fa-plus"></i> 添加
                                    </a>
                                    <table id="flowsteppage-table"></table>
                                </div>
                            </div>
                            <!--流程配置第四步-->
                            <div id="step-4" class="tab-pane" role="tabpanel" aria-labelledby="step-4"
                                 style="height:600px;">
                                <div class="col-sm-6 select-table table-striped" style="float: left;width: 44%;">
                                    <span><b>流程步骤列表</b></span>
                                    <table id="flowstep-table4"></table>
                                </div>
                                <div class="col-sm-6 select-table table-striped" style="float: right;width: 55%;">

                                    <div class="form-group">
                                        <a class="btn btn-success" onclick="addSkip()">
                                            <i class="fa fa-plus"></i> 添加
                                        </a>
                                    </div>
                                    <div style="padding-bottom: 8px;" class="form-group">
                                        <label class="col-sm-3 control-label">多条件组合逻辑：</label>
                                        <div class="col-sm-6">
                                            <div class="radio-box radiowrap"
                                                 th:each="dict : ${@dict.getType('wflstepskip_group_type')}"
                                                 onclick="groupTypeChange()">
                                                <input style="top: 0;" type="radio" id="groupType"
                                                       name="groupType" th:value="${dict.dictValue}">
                                                <label th:for="${'groupType_' + dict.dictCode}"
                                                       th:text="${dict.dictLabel}"></label>
                                            </div>
                                        </div>
                                    </div>
                                    <table id="flowstepskip-table"></table>
                                </div>
                            </div>
                            <!--流程配置第五步-->
                            <div id="step-5" class="tab-pane" role="tabpanel" aria-labelledby="step-5"
                                 style="height:600px;">
                                <div class="col-sm-6 select-table table-striped" style="float: left;width: 44%;">
                                    <span><b>流程步骤列表</b></span>
                                    <table id="flowstep-table5"></table>
                                </div>
                                <div class="col-sm-6 select-table table-striped" style="float: right;width: 55%;">
                                    <a class="btn btn-success" onclick="addLogic()">
                                        <i class="fa fa-plus"></i> 添加
                                    </a>
                                    <table id="flowsteplogic-table"></table>
                                </div>
                            </div>
                            <!--流程配置第六步-->
                            <div id="step-6" class="tab-pane" role="tabpanel" aria-labelledby="step-6"
                                 style="height:600px;">
                                <div class="col-sm-6 select-table table-striped" style="float: left;width: 44%;">
                                    <span><b>流程步骤列表</b></span>
                                    <table id="flowstep-table6"></table>
                                </div>
                                <div class="col-sm-6 select-table table-striped" style="float: right;width: 55%;">
                                    <a class="btn btn-success" onclick="addDoc()">
                                        <i class="fa fa-plus"></i> 添加
                                    </a>
                                    <table id="flowstepdoc-table"></table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: jquery-smartwizard-js"/>
<th:block th:include="include :: jquery-cxselect-js"/>
<script th:inline="javascript">
    var compareTypeDatas = [[${@dict.getType('wflstepskip_compare_type')}]];
    var compareValTypeDatas = [[${@dict.getType('wfl_compare_val_type')}]];
    var logicTypeDatas = [[${@dict.getType('wfl_logic_type')}]];
    var runStsDatas = [[${@dict.getType('wfl_run_sts')}]];
    var isMustDatas = [[${@dict.getType('common_yes_no')}]];
    $(document).ready(function () {
        // 工具栏按钮
        var btnFinish = $('<a id="btn-finish"></a>').text('完成')
            .addClass('btn btn-info')
            .on('click', function () {
                submit();
            });
        var btnCancel = $('<a id="btn-cancel"></a>').text('取消')
            .addClass('btn btn-danger')
            .on('click', function () {
                $('#smartwizard').smartWizard("reset");
            });
        // 下面两个按钮是为了因为插件默认的是botton,这里换成<a>,也可以选择用样式替换,或者不替换
        var btnNext = $('<a id="btn-next"></a>').text('下一步')
            .addClass('btn btn-info')
            .on('click', function () {
                $('#smartwizard').smartWizard("next");
            });
        var btnPrev = $('<a id="btn-prev"></a>').text('上一步')
            .addClass('btn btn-success disabled')
            .on('click', function () {
                $('#smartwizard').smartWizard("prev");
            });
        // 初始化表单向导组件
        $('#smartwizard').smartWizard({
            theme: 'arrows', // default, arrows, dots, progress
            autoAdjustHeight: false, // 自动调整高度, 默认true
            enableURLhash: false, //开启URL hash,开启后点击浏览器前进后退按钮会执行下一步和上一步操作
            transition: {
                animation: 'slide-horizontal', // Effect on navigation, none/fade/slide-horizontal/slide-vertical/slide-swing
            },
            toolbarSettings: {
                showNextButton: false,// 因为上面自定义了下一步按钮, 所以隐藏掉插件自带的按钮, 如果不使用自定义按钮, 需要改为true或者去掉该属性
                showPreviousButton: false,// 因为上面自定义了上一步按钮, 所以隐藏掉插件自带的按钮, 如果不使用自定义按钮, 需要改为true或者去掉该属性
                toolbarExtraButtons: [btnCancel, btnPrev, btnNext, btnFinish]// 扩展的按钮集合
            }
        });
    });

    function submit() {
        var versionId = $("#versionId").val();
        var flowId = $("#flowId").val();
        var rmsg;
        $.ajax({
            type: "post",
            async: false,
            url: ctx + "workflow/flowversion/checkconfigstep/",
            data: {
                "flowId": flowId,
                "versionId": versionId,
                "configStepNum": 6,
            },
            success: function (r) {
                rmsg = r;
            }
        });
        if (rmsg.code == web_status.SUCCESS) {
            $.modal.closeTab();
        } else {
            $.modal.closeLoading();
            $('.imgcode').click();
            $(".code").val("");
            $.modal.alertWarning(rmsg.msg);
        }
    }

    // 显示步骤时将触发事件
    $("#smartwizard").on("showStep", function (e, anchorObject, stepNumber, stepDirection, stepPosition) {

        // 下面按钮是工具栏的
        $("#btn-prev").removeClass('disabled');
        $("#btn-next").removeClass('disabled');
        $("#btn-finish").removeClass('disabled');
        if (stepPosition === 'first') {
            $("#btn-prev").addClass('disabled');
            $("#btn-finish").addClass('disabled');
        } else if (stepPosition === 'last') {
            $("#btn-next").addClass('disabled');
        } else {
            $("#btn-prev").removeClass('disabled');
            $("#btn-next").removeClass('disabled');
            $("#btn-finish").addClass('disabled');
        }
    });

    // 该事件在离开某个步骤之前触发
    $("#smartwizard").on("leaveStep", function (e, anchorObject, currentStepNumber, nextStepNumber, stepDirection) {
        if (stepDirection == 'forward') {
            var flowId = $("#flowId").val();
            var versionId = $("#versionId").val();
            var rmsg;
            $.ajax({
                type: "post",
                async: false,
                url: ctx + "workflow/flowversion/checkconfigstep/",
                data: {
                    "flowId": flowId,
                    "versionId": versionId,
                    "configStepNum": currentStepNumber + 1,
                },
                success: function (r) {
                    rmsg = r;

                }
            });
            if (rmsg.code == web_status.SUCCESS) {
                $("#flowstep-table" + (currentStepNumber + 2)).bootstrapTable('refresh');
                configStepChange(currentStepNumber + 2, 1);
                return true;
            } else {
                $.modal.closeLoading();
                $('.imgcode').click();
                $(".code").val("");
                $.modal.alertWarning(rmsg.msg);
                return false;
            }
        }
        return true;
    });

    $("#theme-selector").on("change", function () {
        // Change theme
        var options = {
            theme: $(this).val()
        };
        $('#smartwizard').smartWizard("setOptions", options);
        return true;
    });

    $("#reset-btn").on("click", function () {
        // Reset wizard
        $('#smartwizard').smartWizard("reset");
        return true;
    });

    $("#prev-btn").on("click", function () {
        // Navigate previous
        $('#smartwizard').smartWizard("prev");
        return true;
    });

    $("#next-btn").on("click", function () {
        // Navigate next
        $('#smartwizard').smartWizard("next");
        return true;
    });

    var prefix = ctx + "workflow/flowversion";
    $(function () {
        var alternativeOptions = {
            url: prefix + "/noChoiceList/",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            id: "alternative-step-table",
            modalName: "备选流程节点",
            columns: [{
                checkbox: true
            },
                {
                    field: 'stepId',
                    title: '节点编号'
                },
                {
                    field: 'stepName',
                    title: '节点名称'
                },
                {
                    field: 'stepDesc',
                    title: '节点说明'
                }]
        };
        var selectedOptions = {
            url: prefix + "/choiceList/",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            id: "selected-step-table",
            modalName: "已选流程节点",
            columns: [{
                checkbox: true
            }, {
                field: 'versionId',
                title: '流程版本号',
                visible: false
            },
                {
                    field: 'stepId',
                    title: '节点编号'
                },
                {
                    field: 'stepName',
                    title: '节点名称'
                },
                {
                    field: 'orderNum',
                    title: '节点顺序'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="upStep(\'' + row.versionId + '\',\'' + row.stepId + '\',\'' + row.orderNum + '\')"><i class="fa fa-arrow-up"></i>上移</a> ');
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="downStep(\'' + row.versionId + '\',\'' + row.stepId + '\',\'' + row.orderNum + '\')"><i class="fa fa-arrow-down"></i>下移</a> ');
                        return actions.join('');
                    }
                }]
        };
        var flowstepOptions2 = {
            url: prefix + "/choiceList/",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            onClickCell: onClickCellApprov,
            id: "flowstep-table2",
            modalName: "流程节点",
            columns: [{
                checkbox: true
            },
                {
                    field: 'stepId',
                    title: '节点编号'
                },
                {
                    field: 'stepName',
                    title: '节点名称'
                },
                {
                    field: 'orderNum',
                    title: '节点顺序'
                }]
        };
        var flowstepOptions3 = {
            url: prefix + "/choiceList/",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            onClickCell: onClickCellPage,
            id: "flowstep-table3",
            modalName: "流程节点",
            columns: [{
                checkbox: true
            },
                {
                    field: 'stepId',
                    title: '节点编号'
                },
                {
                    field: 'stepName',
                    title: '节点名称'
                },
                {
                    field: 'orderNum',
                    title: '节点顺序'
                }]
        };
        var flowstepOptions4 = {
            url: prefix + "/choiceList/",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            onClickCell: onClickCellSkip,
            id: "flowstep-table4",
            modalName: "流程节点",
            columns: [{
                checkbox: true
            },
                {
                    field: 'stepId',
                    title: '节点编号'
                },
                {
                    field: 'stepName',
                    title: '节点名称'
                },
                {
                    field: 'orderNum',
                    title: '节点顺序'
                },
                {
                    field: 'groupType',
                    title: '多条件组合逻辑',
                    visible: false
                }]
        };
        var flowstepOptions5 = {
            url: prefix + "/choiceList/",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            onClickCell: onClickCellLogic,
            id: "flowstep-table5",
            modalName: "流程节点",
            columns: [{
                checkbox: true
            },
                {
                    field: 'stepId',
                    title: '节点编号'
                },
                {
                    field: 'stepName',
                    title: '节点名称'
                },
                {
                    field: 'orderNum',
                    title: '节点顺序'
                }]
        };
        var flowstepOptions6 = {
            url: prefix + "/choiceList/",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            onClickCell: onClickCellDoc,
            id: "flowstep-table6",
            modalName: "流程节点",
            columns: [{
                checkbox: true
            },
                {
                    field: 'stepId',
                    title: '节点编号'
                },
                {
                    field: 'stepName',
                    title: '节点名称'
                },
                {
                    field: 'orderNum',
                    title: '节点顺序'
                }]
        };
        var flowStepPageOptions = {
            url: prefix + "/pageList/",
            removeUrl: ctx + "workflow/steppage/remove",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            queryParams: function (params) {
                return {
                    pageSize: params.pageSize,
                    pageNumber: params.pageNumber,
                    versionId: $('#versionId').val(),
                    orderNum: $('#orderNum').val(),
                };
            },
            id: "flowsteppage-table",
            modalName: "流程节点页面配置",
            columns: [{
                checkbox: true
            },
                {
                    field: 'versionId',
                    title: '流程版本号',
                    visible: false
                },
                {
                    field: 'stepId',
                    title: '节点编号',
                    visible: false
                },

                {
                    field: 'pageId',
                    title: '模板页面编号'
                },
                {
                    field: 'pageName',
                    title: '模板页面名称'
                },
                {
                    field: 'isOnlyRead',
                    title: '页面只读',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return isOnlyreadTools(row);
                    }
                },
                {
                    field: 'isCheck',
                    title: '页面校验',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return isCheckTools(row);
                    }
                },
                {
                    field: 'orderNum',
                    title: '页面顺序'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="movePage(\'' + row.versionId + '\',\'' + row.stepId + '\',\'' + row.pageId + '\',\'' + row.orderNum + '\',\'up\')"><i class="fa fa-arrow-up"></i>上移</a> ');
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="movePage(\'' + row.versionId + '\',\'' + row.stepId + '\',\'' + row.pageId + '\',\'' + row.orderNum + '\',\'down\')"><i class="fa fa-arrow-down"></i>下移</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="deletePage(\'' + row.versionId + '\',\'' + row.stepId + '\',\'' + row.pageId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        var flowStepSkipOptions = {
            url: prefix + "/skipList/",
            updateUrl: ctx + "workflow/stepskip/edit/{id}",
            removeUrl: ctx + "workflow/stepskip/remove",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            queryParams: function (params) {
                return {
                    pageSize: params.pageSize,
                    pageNumber: params.pageNumber,
                    versionId: $('#versionId').val(),
                    orderNum: $('#orderNum').val(),
                };
            },
            id: "flowstepskip-table",
            modalName: "流程节点跳转配置",
            columns: [{
                checkbox: true
            },
                {
                    field: 'conditionId',
                    title: '条件编号',
                    visible: false
                },
                {
                    field: 'versionId',
                    title: '流程版本号',
                    visible: false
                },
                {
                    field: 'stepId',
                    title: '流程节点编号',
                    visible: false
                },
                {
                    field: 'conditionDesc',
                    title: '条件说明'
                },
                {
                    field: 'valSql',
                    title: '取值SQL'
                },
                {
                    field: 'compareType',
                    title: '比较类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(compareTypeDatas, value);
                    }
                },
                {
                    field: 'compareVal',
                    title: '比较值'
                },
                {
                    field: 'compareValType',
                    title: '比较值类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(compareValTypeDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.conditionId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.conditionId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        var flowStepLogicOptions = {
            url: prefix + "/logicList/",
            updateUrl: ctx + "workflow/steplogic/edit/{id}",
            removeUrl: ctx + "workflow/steplogic/remove",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            queryParams: function (params) {
                return {
                    pageSize: params.pageSize,
                    pageNumber: params.pageNumber,
                    versionId: $('#versionId').val(),
                    orderNum: $('#orderNum').val(),
                };
            },
            id: "flowsteplogic-table",
            modalName: "流程节点逻辑配置",
            columns: [{
                checkbox: true
            },
                {
                    field: 'logicId',
                    title: '逻辑编号',
                    visible: false
                },
                {
                    field: 'versionId',
                    title: '流程版本号',
                    visible: false
                },
                {
                    field: 'stepId',
                    title: '流程节点编号',
                    visible: false
                },
                {
                    field: 'logicType',
                    title: '逻辑类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(logicTypeDatas, value);
                    }
                },
                {
                    field: 'riskStrategy',
                    title: '风险策略'
                },
                {
                    field: 'className',
                    title: '外部类名称'
                },
                {
                    field: 'methodName',
                    title: '外部类方法名'
                },
                {
                    field: 'runSts',
                    title: '执行时点',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(runStsDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="editLogic(\'' + row.logicId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.logicId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        var flowStepDocOptions = {
            url: prefix + "/docList/",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            queryParams: function (params) {
                return {
                    pageSize: params.pageSize,
                    pageNumber: params.pageNumber,
                    versionId: $('#versionId').val(),
                    orderNum: $('#orderNum').val()
                };
            },
            id: "flowstepdoc-table",
            modalName: "流程节点影像上传配置",
            columns: [{
                checkbox: true
            },
                {
                    field: 'versionId',
                    title: '流程版本号',
                    visible: false
                },
                {
                    field: 'stepId',
                    title: '节点编号',
                    visible: false
                },
                {
                    field: 'docId',
                    title: '资料编号'
                },
                {
                    field: 'docCode',
                    title: '资料编码'
                },
                {
                    field: 'docName',
                    title: '资料名称'
                },
                {
                    field: 'orderNum',
                    title: '序号',
                    visible: false
                },
                {
                    field: 'isMust',
                    title: '是否必传',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return isMustTools(row);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="deleteDoc(\'' + row.versionId + '\',\'' + row.stepId + '\',\'' + row.docId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(alternativeOptions);
        $.table.init(selectedOptions);
        $.table.init(flowstepOptions2);
        $.table.init(flowstepOptions3);
        $.table.init(flowstepOptions4);
        $.table.init(flowstepOptions5);
        $.table.init(flowstepOptions6);
        $.table.init(flowStepPageOptions);
        $.table.init(flowStepSkipOptions);
        $.table.init(flowStepLogicOptions);
        $.table.init(flowStepDocOptions);

    });

    //  获取选择的步骤初始化到步骤表
    function selectStep() {
        var rows = $("#alternative-step-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请在备选步骤列表选择流程节点！");
            return;
        }
        var versionId = $("#versionId").val();
        $.ajax({
            type: "post",
            url: ctx + "workflow/flowstep/addStep/",
            data: {
                "versionId": versionId,
                "stepJson": JSON.stringify(rows),
            },
            success: function (r) {
                if (r.code == web_status.SUCCESS) {
                    $("#alternative-step-table").bootstrapTable('refresh');
                    $("#selected-step-table").bootstrapTable('refresh');
                    $.modal.msgSuccess(r.msg);
                } else {
                    $.modal.closeLoading();
                    $('.imgcode').click();
                    $(".code").val("");
                    $.modal.alertWarning(r.msg);
                }
            }
        });
    }

    //  移除已选流程节点
    function removeStep() {
        var rows = $("#selected-step-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请在已选步骤列表选择需要移除的流程节点！");
            return;
        }
        var versionId = $("#versionId").val();
        $.modal.confirm("确定移除所选流程节点吗？", function () {
            $.ajax({
                type: "post",
                url: ctx + "workflow/flowstep/remove/",
                data: {
                    "versionId": versionId,
                    "stepJson": JSON.stringify(rows),
                },
                success: function (r) {
                    if (r.code == web_status.SUCCESS) {
                        $("#alternative-step-table").bootstrapTable('refresh');
                        $("#selected-step-table").bootstrapTable('refresh');
                        $.modal.msgSuccess(r.msg);
                    } else {
                        $.modal.closeLoading();
                        $('.imgcode').click();
                        $(".code").val("");
                        $.modal.msg(r.msg);
                    }
                }
            });
        });
    }

    //  上移流程节点
    function upStep(versionId, stepId, orderNum) {
        if (orderNum == 1) {
            $.modal.alertWarning("第一个节点无法上移！");
            return;
        }
        $.modal.confirm("确定上移流程节点吗？", function () {
            $.ajax({
                type: "post",
                url: ctx + "workflow/flowstep/up/",
                data: {
                    "versionId": versionId,
                    "stepId": stepId,
                    "orderNum": orderNum,
                },
                success: function (r) {
                    if (r.code == web_status.SUCCESS) {
                        $("#selected-step-table").bootstrapTable('refresh');
                        $.modal.msgSuccess(r.msg);
                    } else {
                        $.modal.closeLoading();
                        $('.imgcode').click();
                        $(".code").val("");
                        $.modal.alertWarning(r.msg);
                    }
                }
            });
        });
    }

    //  下移流程节点
    function downStep(versionId, stepId, orderNum) {
        $.modal.confirm("确定下移流程节点吗？", function () {
            $.ajax({
                type: "post",
                url: ctx + "workflow/flowstep/down/",
                data: {
                    "versionId": versionId,
                    "stepId": stepId,
                    "orderNum": orderNum,
                },
                success: function (r) {
                    if (r.code == web_status.SUCCESS) {
                        $("#selected-step-table").bootstrapTable('refresh');
                        $.modal.msgSuccess(r.msg);
                    } else {
                        $.modal.closeLoading();
                        $('.imgcode').click();
                        $(".code").val("");
                        $.modal.alertWarning(r.msg);
                    }
                }
            });
        });
    }


    //切换任务方案
    function taskModeChange(taskPosition) {
        var taskMode = $("#taskMode").val();
        var taskPositionStr = '<option value="">请选择任务定位</option>';
        var userTaskPosition = '[{"id":"1","text":"当前用户本人"},{"id":"2","text":"关联步提交人"},{"id":"3","text":"自定义SQL"}]';
        var userTaskPositionJson = JSON.parse(userTaskPosition);
        var roleTaskPosition = '[{"id":"4","text":"当前机构指定岗位"},{"id":"5","text":"上级机构指定岗位"},{"id":"6","text":"指定机构指定岗位"},{"id":"7","text":"任意机构指定岗位"}]'
        var roleTaskPositionJson = JSON.parse(roleTaskPosition);
        if (taskMode == 1) {//选人员
            //设置审批机构只读，清空赋值
            $("#taskOrgName").attr("disabled", "disabled");
            $("#taskOrgId").val("");
            $("#taskOrgName").val("");
            for (var i = 0; i < userTaskPositionJson.length; i++) {
                if (userTaskPositionJson[i].id == taskPosition) {
                    taskPositionStr += '<option value="' + userTaskPositionJson[i].id + '" selected="selected">' + userTaskPositionJson[i].text + '</option>';//当ids中的一项等于目标id时，option设置selected="selected"
                } else {
                    taskPositionStr += '<option value="' + userTaskPositionJson[i].id + '">' + userTaskPositionJson[i].text + '</option>';
                }
            }
        } else {//选岗位
            $("#taskOrgName").removeAttr("disabled");
            $("#defineSql").attr("disabled", "disabled");
            $("#defineSql").val("");
            for (var i = 0; i < roleTaskPositionJson.length; i++) {
                if (roleTaskPositionJson[i].id == taskPosition) {
                    taskPositionStr += '<option value="' + roleTaskPositionJson[i].id + '" selected="selected">' + roleTaskPositionJson[i].text + '</option>';//当ids中的一项等于目标id时，option设置selected="selected"
                } else {
                    taskPositionStr += '<option value="' + roleTaskPositionJson[i].id + '">' + roleTaskPositionJson[i].text + '</option>';
                }
            }
        }
        //将动态拼接的数据渲染任务定位下拉框
        $('#taskPosition').html(taskPositionStr);
        // if (taskPosition == "" || taskPosition == "null") {//切换任务方案下拉框时执行
        //     //刷新任务定位下拉框
        //     //$('#taskPosition').selectpicker('refresh');
        // }

    }

    //切换任务定位
    function taskPositionChange(taskIndex) {
        var taskPosition = $("#taskPosition").val();
        var taskMode = $("#taskMode").val();
        var versionId = $("#versionId").val();
        var orderNum = $("#orderNum").val();
        $.ajax({
            type: "post",
            url: ctx + "workflow/flowstep/taskindex/",
            data: {
                "taskMode": taskMode,
                "versionId": versionId,
                "orderNum": orderNum,
                "taskIndex": taskIndex,
            },
            success: function (r) {
                if (r.code == web_status.SUCCESS) {
                    var taskIndexStr = '';
                    if (taskPosition == 1) { //当前用户本人
                        $("#taskOrgName").attr("disabled", "disabled");
                        $("#taskOrgId").val("");
                        $("#taskOrgName").val("");
                        $("#taskIndex").attr("disabled", "disabled");
                        $("#taskIndex").val("");
                        $("#defineSql").attr("disabled", "disabled");
                        $("#defineSql").val("");

                    } else if (taskPosition == 2) {//关联步提交人
                        $("#taskOrgName").attr("disabled", "disabled");
                        $("#taskOrgId").val("");
                        $("#taskOrgName").val("");
                        $("#taskIndex").removeAttr("disabled");
                        $("#defineSql").attr("disabled", "disabled");
                        $("#defineSql").val("");
                        //拼接步骤
                        taskIndexStr = r.msg;
                    } else if (taskPosition == 3) {//自定义SQL
                        $("#taskOrgName").attr("disabled", "disabled");
                        $("#taskOrgId").val("");
                        $("#taskOrgName").val("");
                        $("#taskIndex").attr("disabled", "disabled");
                        $("#taskIndex").val("");
                        $("#defineSql").removeAttr("disabled");
                    } else if (taskPosition == 4) {//当前机构指定岗位
                        $("#taskOrgName").attr("disabled", "disabled");
                        $("#taskOrgId").val("");
                        $("#taskOrgName").val("");
                        $("#taskIndex").removeAttr("disabled");
                        taskIndexStr = r.msg;
                    } else if (taskPosition == 5) {//上级机构指定岗位
                        $("#taskOrgName").attr("disabled", "disabled");
                        $("#taskOrgId").val("");
                        $("#taskOrgName").val("");
                        $("#taskIndex").removeAttr("disabled");
                        taskIndexStr = r.msg;
                    } else if (taskPosition == 6) {//指定机构指定岗位
                        $("#taskOrgName").removeAttr("disabled");
                        $("#taskIndex").removeAttr("disabled");
                        taskIndexStr = r.msg;
                    } else if (taskPosition == 7) {//任意机构指定岗位
                        $("#taskOrgName").attr("disabled", "disabled");
                        $("#taskOrgId").val("");
                        $("#taskOrgName").val("");
                        $("#taskIndex").removeAttr("disabled");
                        taskIndexStr = r.msg;
                    }
                    //将动态拼接的数据渲染任务索引下拉框
                    $('#taskIndex').html(taskIndexStr);
                    // if (taskIndex == "" || taskIndex == "null") {//切换任务定位下拉框时执行
                    //     //刷新任务索引下拉框
                    //     $('#taskIndex').selectpicker('refresh');
                    // }

                } else {
                    $.modal.alertWarning(r.msg);
                }
            }
        });

    }

    //切换分配策略
    function taskPolicyChange() {
        var taskPolicy = $("#taskPolicy").val();
        if (taskPolicy == 1) {//任务抢先
            $("#approvMode").attr("disabled", "disabled");
            $("#approvMode").val("");
            $("#approvPop").attr("disabled", "disabled");
            $("#approvPop").val("");
            $("#passPop").attr("disabled", "disabled");
            $("#passPop").val("");
        } else {//并发
            $("#approvMode").removeAttr("disabled");
            $("#approvPop").removeAttr("disabled");
            $("#passPop").removeAttr("disabled");
        }
    }

    //切换并发审批模式
    function approvModeChange() {
        var approvMode = $("#approvMode").val();
        if (approvMode == 1) {//正常模式
            $("#passPop").attr("disabled", "disabled");
            $("#passPop").val("");
        } else {//投票模式
            $("#passPop").removeAttr("disabled");
        }
    }

    //2-流程审批配置切换步骤编号
    function onClickCellApprov(field, value, row, $element) {
        var orderNum = row.orderNum;
        $("#orderNum").val(orderNum);
        var form = $("#step-2").find('.form');
        if (form.validate().form()) {
            $("#flowstep-table2").bootstrapTable('uncheckAll');
            $('#flowstep-table2').bootstrapTable('checkBy', {field: 'orderNum', values: [orderNum]});
            getWflApprovInfo(orderNum);
        }
    }

    //获取步骤审批配置信息
    function getWflApprovInfo(orderNum) {
        var versionId = $("#versionId").val();
        $.ajax({
            type: "post",
            url: ctx + "workflow/flowstep/wflapprovinfo/",
            data: {
                "versionId": versionId,
                "orderNum": orderNum,
            },
            success: function (r) {
                if (r.code == web_status.SUCCESS) {
                    var wflapprovinfo = eval('(' + r.msg + ')');
                    // 节点编号
                    var stepId = wflapprovinfo.stepId;
                    $("#stepId").val(stepId);
                    // 任务方案
                    var taskMode = wflapprovinfo.taskMode;
                    $("#taskMode").val(taskMode);
                    // 任务定位
                    var taskPosition = wflapprovinfo.taskPosition;

                    //切换任务方案
                    taskModeChange(taskPosition);
                    //审批机构
                    var taskOrgId = wflapprovinfo.taskOrgId;
                    var taskOrgName = wflapprovinfo.taskOrgName;
                    $("#taskOrgId").val(taskOrgId);
                    $("#taskOrgName").val(taskOrgName);
                    //任务索引
                    var taskIndex = wflapprovinfo.taskIndex;
                    //触发切换任务定位
                    taskPositionChange(taskIndex);
                    // 分配策略
                    var taskPolicy = wflapprovinfo.taskPolicy;
                    $("#taskPolicy").val(taskPolicy);
                    // 自定义SQL
                    var defineSql = wflapprovinfo.defineSql;
                    $("#defineSql").val(defineSql);
                    // 审批权限
                    var approvPower = wflapprovinfo.approvPower;
                    //获取节点审批权限列表
                    getWflApprovList(versionId, stepId, approvPower);
                    // 过滤上步提交人
                    var laststepFilter = wflapprovinfo.laststepFilter;
                    $("#laststepFilter").val(laststepFilter);
                    // 并发审批模式
                    var approvMode = wflapprovinfo.approvMode;
                    $("#approvMode").val(approvMode);
                    // 参与人数(任务并发使用)
                    var approvPop = wflapprovinfo.approvPop;
                    $("#approvPop").val(approvPop);
                    // 通过人数
                    var passPop = wflapprovinfo.passPop;
                    $("#passPop").val(passPop);
                    //触发联动切换事件
                    taskPolicyChange();
                    //审批限时(小时)
                    var timeLimit = wflapprovinfo.timeLimit;
                    $("#timeLimit").val(timeLimit);

                } else {
                    $.modal.closeLoading();
                    $('.imgcode').click();
                    $(".code").val("");
                    $.modal.alertWarning(r.msg);
                }
            }
        });

    }

    //获取节点审批权限列表
    function getWflApprovList(versionId, stepId, approvPower) {
        $.ajax({
            type: "post",
            url: ctx + "workflow/flowstep/wflapprovlist/",
            data: {
                "versionId": versionId,
                "stepId": stepId,
            },
            success: function (r) {
                if (r.code == web_status.SUCCESS) {
                    var data = JSON.parse(r.msg)
                    // 返回data成功后
                    $('#approvPowerDiv').empty()
                    for (var i = 0; i < data.length; i++) {
                        var returnStepId = data[i].returnStepId == null ? "" : data[i].returnStepId;
                        var approvCode = data[i].approvCode;
                        var approvPowerValue = approvCode + returnStepId;
                        var approv = approvPower == null ? "" : approvPower.split(',');
                        if (approv.includes(approvPowerValue) ) {
                            $('#approvPowerDiv').append(
                                '<div><lable  class="check-box">' +
                                '<input name="approvPower" id="approvPower' + i + '" type="checkbox" checked="' + approvPowerValue + '"  value="' + approvPowerValue + '" required/>&nbsp;' + data[i].approvDesc
                                + '</lable></div>'
                            );
                        } else {
                            $('#approvPowerDiv').append(
                                '<div><lable  class="check-box">' +
                                '<input name="approvPower" id="approvPower' + i + '" type="checkbox"  value="' + approvPowerValue + '" required/>&nbsp;' + data[i].approvDesc
                                + '</lable></div>'
                            );
                        }
                    }
                } else {
                    $.modal.closeLoading();
                    $('.imgcode').click();
                    $(".code").val("");
                    $.modal.alertWarning(r.msg);
                }
            }
        });
    }

    //保存流程审批配置信息
    function saveWflApprovInfo() {
        var data = $('#form-flowstep-add').serializeArray();
        var versionId = $("#versionId").val();
        data.push({"name": "versionId", "value": versionId});
        var form = $("#step-2").find('.form');
        if (form.validate().form()) {
            // 任务方案
            var taskMode = $("#taskMode").val();
            // 任务定位
            var taskPosition = $("#taskPosition").val();
            //任务索引
            var taskIndex = $("#taskIndex").val();
            if ((taskPosition == 2 || taskMode == 2) && taskIndex == "") {
                $.modal.alertWarning("请选择任务索引！");
                return;
            }
            //审批机构
            var taskOrgId = $("#taskOrgId").val();
            var taskOrgName = $("#taskOrgName").val();
            if (taskPosition == 6 && (taskOrgId == "" || taskOrgName == "")) {
                $.modal.alertWarning("请选择审批机构！");
                return;
            }

            // 自定义SQL
            var defineSql = $("#defineSql").val();
            if (taskPosition == 3 && taskIndex == "") {
                $.modal.alertWarning("请填写自定义SQL！");
                return;
            }

            // 分配策略
            var taskPolicy = $("#taskPolicy").val();
            // 并发审批模式
            var approvMode = $("#approvMode").val();
            if ((taskPolicy == 2 || taskPolicy == 3) && approvMode == "") {
                $.modal.alertWarning("请选择并发审批模式！");
                return;
            }
            // 参与人数(任务并发使用)
            var approvPop = $("#approvPop").val();
            if ((taskPolicy == 2 || taskPolicy == 3) && (approvPop == "" || approvPop == 0)) {
                $.modal.alertWarning("参与人数必须大于0！");
                return;
            }

            // 通过人数
            var passPop = $("#passPop").val();
            if (approvMode == 2 && (passPop == "" || passPop == 0)) {
                $.modal.alertWarning("通过人数必须大于0！");
                return;
            }
            $.ajax({
                type: "post",
                url: ctx + "workflow/flowstep/edit/",
                data: data,
                success: function (r) {
                    if (r.code == web_status.SUCCESS) {
                        $.modal.msgSuccess(r.msg);
                    } else {
                        $.modal.closeLoading();
                        $('.imgcode').click();
                        $(".code").val("");
                        $.modal.alertWarning(r.msg);
                    }
                }
            });
        }
    }

    //3-流程页面配置切换步骤编号
    function onClickCellPage(field, value, row, $element) {
        var orderNum = row.orderNum;
        var orderNum = row.orderNum;
        $("#orderNum").val(orderNum);
        $("#stepId").val(row.stepId);
        $("#flowstep-table3").bootstrapTable('uncheckAll');
        $('#flowstep-table3').bootstrapTable("checkBy", {field: 'orderNum', values: [orderNum]});
        $('#flowsteppage-table').bootstrapTable('refresh');
    }

    //4-流程跳转配置切换步骤编号
    function onClickCellSkip(field, value, row, $element) {
        var orderNum = row.orderNum;
        var orderNum = row.orderNum;
        $("#orderNum").val(orderNum);
        $("#stepId").val(row.stepId);
        $("#flowstep-table4").bootstrapTable('uncheckAll');
        $('#flowstep-table4').bootstrapTable("checkBy", {field: 'orderNum', values: [orderNum]});
        $('#flowstepskip-table').bootstrapTable('refresh');

        //多条件组合逻辑
        var groupType = row.groupType;
        //移除已选项
        $(':radio[name=groupType]').parent().toggleClass('checked', false);
        if (groupType == 1) {
            $(':radio[name=groupType][value=1]').parent().addClass('checked').prop("checked", true);
        }
        if (groupType == 2) {
            $(':radio[name=groupType][value=2]').parent().addClass('checked').prop("checked", true);

        }
    }

    //更改多条件组合逻辑
    $("input:radio[name='groupType']").on('ifChecked', function (event) {
        var versionId = $("#versionId").val();
        var stepId = $("#stepId").val();
        var groupType = $(this).val();
        $.operate.post(ctx + "workflow/flowstep/edit", {
            "versionId": versionId,
            "stepId": stepId,
            "groupType": groupType
        });
        $('#flowstep-table4').bootstrapTable('refresh');
    });

    //获取步骤跳转配置信息
    function getWflSkipInfo(orderNum) {
        var versionId = $("#versionId").val();
        $.ajax({
            type: "post",
            url: ctx + "workflow/flowstep/wflapprovinfo/",
            data: {
                "versionId": versionId,
                "orderNum": orderNum,
            },
            success: function (r) {
                if (r.code == web_status.SUCCESS) {
                    var wflapprovinfo = eval('(' + r.msg + ')');
                    // 节点编号
                    var stepId = wflapprovinfo.stepId;
                    $("#stepId").val(stepId);
                    //多条件组合逻辑
                    var groupType = wflapprovinfo.groupType;
                    $("input[name='groupType']").removeAttr('checked');
                    if (groupType == 1) {
                        $(':radio[name=groupType][value=1]').parent().addClass('checked').prop("checked", true);
                    }
                    if (groupType == 2) {
                        $(':radio[name=groupType][value=2]').parent().addClass('checked').prop("checked", true);

                    }
                } else {
                    $.modal.closeLoading();
                    $('.imgcode').click();
                    $(".code").val("");
                    $.modal.alertWarning(r.msg);
                }
            }
        });
    }

    //5-流程逻辑配置切换步骤编号
    function onClickCellLogic(field, value, row, $element) {
        var orderNum = row.orderNum;
        $("#orderNum").val(orderNum);
        $("#stepId").val(row.stepId);
        $("#flowstep-table5").bootstrapTable('uncheckAll');
        $('#flowstep-table5').bootstrapTable("checkBy", {field: 'orderNum', values: [orderNum]});
        $('#flowsteplogic-table').bootstrapTable('refresh');
    }

    //获取步骤逻辑配置信息
    function getWflLogicInfo(orderNum) {

    }

    //6-流程影像配置切换步骤编号
    function onClickCellDoc(field, value, row, $element) {
        var orderNum = row.orderNum;
        $("#orderNum").val(orderNum);
        $("#stepId").val(row.stepId);
        $("#flowstep-table6").bootstrapTable('uncheckAll');
        $('#flowstep-table6').bootstrapTable("checkBy", {field: 'orderNum', values: [orderNum]});
        $('#flowstepdoc-table').bootstrapTable('refresh');
    }

    //获取步骤影像配置信息
    function getWflDocInfo(orderNum) {

    }

    //流程配置步骤切换触发事件,参数(流程配置步骤，流程节点序号)
    function configStepChange(configStepNum, wflStepOrderNum) {
        $("#orderNum").val(wflStepOrderNum);
        if (configStepNum == 2) {//第二步审批配置
            getWflApprovInfo(wflStepOrderNum);
        } else if (configStepNum == 3) {//第三步页面配置
            $('#flowsteppage-table').bootstrapTable('refresh');
        } else if (configStepNum == 4) {//第四步跳转配置配置
            $('#flowstepskip-table').bootstrapTable('refresh');
            getWflSkipInfo(wflStepOrderNum);
        } else if (configStepNum == 5) {//第五步逻辑配置
            $('#flowsteplogic-table').bootstrapTable('refresh');
            getWflLogicInfo(wflStepOrderNum);
        } else if (configStepNum == 6) {//第六步影像配置
            $('#flowstepdoc-table').bootstrapTable('refresh');
            getWflDocInfo(wflStepOrderNum);
        }

    }

    /* 选择机构树 */
    function selectDeptTree() {
        var deptId = "100";
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择机构',
            width: "380",
            high: "500",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#taskOrgId").val(body.find('#treeId').val());
        $("#taskOrgName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    //选择页面start
    function addPage() {
        var versionId = $("#versionId").val();
        var orderNum = $("#orderNum").val();
        var options = {
            title: '选择页面模板',
            url: ctx + "workflow/flowversion/checkPage/" + versionId + "/" + orderNum,
            callBack: doSubmitPageList
        };
        $.modal.openOptions(options);
    }

    function doSubmitPageList(index, layero) {
        var rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var versionId = $("#versionId").val();
        var orderNum = $("#orderNum").val();
        var pageIds = rows.join();
        var data = {
            "versionId": versionId,
            "orderNum": orderNum,
            "pageIds": pageIds
        };
        $.operate.save(ctx + "workflow/steppage/add/", data);
        $.modal.close(index);
        $('#flowsteppage-table').bootstrapTable('refresh');
    }

    //选择页面end
    function deletePage(versionId, stepId, pageId) {
        $.modal.confirm("确定删除当前页面吗？", function () {
            $.ajax({
                type: "post",
                url: ctx + "workflow/steppage/remove/",
                data: {
                    "versionId": versionId,
                    "stepId": stepId,
                    "pageId": pageId,
                },
                success: function (r) {
                    if (r.code == web_status.SUCCESS) {
                        $("#flowsteppage-table").bootstrapTable('refresh');
                        $.modal.msgSuccess(r.msg);
                    } else {
                        $.modal.closeLoading();
                        $('.imgcode').click();
                        $(".code").val("");
                        $.modal.alertWarning(r.msg);
                    }
                }
            });
        });
    }

    //移动页面顺序
    function movePage(versionId, stepId, pageId, orderNum, moveType) {
        if (orderNum == 1 && moveType == "up") {
            $.modal.alertWarning("第一个页面无法上移！");
            return;
        }
        $.modal.confirm("确定移动当前页面吗？", function () {
            $.ajax({
                type: "post",
                url: ctx + "workflow/steppage/move/",
                data: {
                    "versionId": versionId,
                    "stepId": stepId,
                    "pageId": pageId,
                    "orderNum": orderNum,
                    "moveType": moveType,
                },
                success: function (r) {
                    if (r.code == web_status.SUCCESS) {
                        $("#flowsteppage-table").bootstrapTable('refresh');
                        $.modal.msgSuccess(r.msg);
                    } else {
                        $.modal.closeLoading();
                        $('.imgcode').click();
                        $(".code").val("");
                        $.modal.alertWarning(r.msg);
                    }
                }
            });
        });
    }

    /* 页面校验状态显示 */
    function isCheckTools(row) {
        if (row.isCheck == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="isCheckEnable(\'' + row.versionId + '\',\'' + row.stepId + '\',\'' + row.pageId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="isCheckDisable(\'' + row.versionId + '\',\'' + row.stepId + '\',\'' + row.pageId + '\')"></i> ';
        }
    }

    /* 页面校验状态停用 */
    function isCheckDisable(versionId, stepId, pageId) {
        $.modal.confirm("确认要停用页面校验吗？", function () {
            $.operate.post(ctx + "workflow/steppage/changeIsCheck", {
                "versionId": versionId,
                "stepId": stepId,
                "pageId": pageId,
                "isCheck": 0
            });
        })
    }

    /* 页面校验状态启用 */
    function isCheckEnable(versionId, stepId, pageId) {
        $.modal.confirm("确认要启用页面校验吗？", function () {
            $.operate.post(ctx + "workflow/steppage/changeIsCheck", {
                "versionId": versionId,
                "stepId": stepId,
                "pageId": pageId,
                "isCheck": "1"
            });
        })
    }

    /* 页面只读状态显示 */
    function isOnlyreadTools(row) {
        if (row.isOnlyRead == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="isOnlyreadEnable(\'' + row.versionId + '\',\'' + row.stepId + '\',\'' + row.pageId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="isOnlyreadDisable(\'' + row.versionId + '\',\'' + row.stepId + '\',\'' + row.pageId + '\')"></i> ';
        }
    }

    /* 页面只读状态停用 */
    function isOnlyreadDisable(versionId, stepId, pageId) {
        $.modal.confirm("确认要停用页面只读吗？", function () {
            $.operate.post(ctx + "workflow/steppage/changeIsOnlyRead", {
                "versionId": versionId,
                "stepId": stepId,
                "pageId": pageId,
                "isOnlyRead": 0
            });
        })
    }

    /* 页面只读状态启用 */
    function isOnlyreadEnable(versionId, stepId, pageId) {
        $.modal.confirm("确认要启用页面只读吗？", function () {
            $.operate.post(ctx + "workflow/steppage/changeIsOnlyRead", {
                "versionId": versionId,
                "stepId": stepId,
                "pageId": pageId,
                "isOnlyRead": 1
            });
        })
    }

    //添加流程节点跳过条件
    function addSkip() {
        var versionId = $("#versionId").val();
        var orderNum = $("#orderNum").val();
        var options = {
            title: '添加跳过条件',
            url: ctx + "workflow/stepskip/add/" + versionId + "/" + orderNum,
            callBack: doSubmitSkip
        };
        $.modal.openOptions(options);
    }

    function doSubmitSkip(index, layero) {
        var result = layero.find("iframe")[0].contentWindow.submitHandler();
        if (result) {
            $("#flowstepskip-table").bootstrapTable('refresh');
            $.modal.close(index);
        }
    }

    //添加流程节点调用逻辑
    function addLogic() {
        var versionId = $("#versionId").val();
        var orderNum = $("#orderNum").val();
        var options = {
            title: '添加调用逻辑',
            url: ctx + "workflow/steplogic/add/" + versionId + "/" + orderNum,
            callBack: doSubmitLogic
        };
        $.modal.openOptions(options);
    }

    //编辑流程节点调用逻辑
    function editLogic(logicId) {
        var options = {
            title: '修改调用逻辑',
            url: ctx + "workflow/steplogic/edit/" + logicId,
            callBack: doSubmitLogic
        };
        $.modal.openOptions(options);
    }

    function doSubmitLogic(index, layero) {
        var result = layero.find("iframe")[0].contentWindow.submitHandler();
        if (result) {
            $("#flowsteplogic-table").bootstrapTable('refresh');
            $.modal.close(index);
        }
    }

    //添加流程节点影像资料配置
    function addDoc() {
        var versionId = $("#versionId").val();
        var orderNum = $("#orderNum").val();
        var options = {
            title: '添加影像资料',
            url: ctx + "workflow/flowversion/checkDocList/" + versionId + "/" + orderNum,
            callBack: doSubmitDoc
        };
        $.modal.openOptions(options);
    }

    function doSubmitDoc(index, layero) {
        var rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var versionId = $("#versionId").val();
        var orderNum = $("#orderNum").val();
        var docIds = rows.join();
        var data = {
            "versionId": versionId,
            "orderNum": orderNum,
            "docIds": docIds
        };
        $.operate.save(ctx + "workflow/stepDoc/add/", data);
        $.modal.close(index);
    }

    function deleteDoc(versionId, stepId, docId) {
        $.modal.confirm("确定删除当前配置吗？", function () {
            $.ajax({
                type: "post",
                url: ctx + "workflow/stepDoc/remove/",
                data: {
                    "versionId": versionId,
                    "stepId": stepId,
                    "docId": docId,
                },
                success: function (r) {
                    if (r.code == web_status.SUCCESS) {
                        $("#flowstepdoc-table").bootstrapTable('refresh');
                        $.modal.msgSuccess(r.msg);
                    } else {
                        $.modal.closeLoading();
                        $('.imgcode').click();
                        $(".code").val("");
                        $.modal.alertWarning(r.msg);
                    }
                }
            });
        });
    }

    /* 影像资料必传状态显示 */
    function isMustTools(row) {
        if (row.isMust == "F") {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="isMustChange(\'' + row.versionId + '\',\'' + row.stepId + '\',\'' + row.docId + '\',\'' + row.isMust + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="isMustChange(\'' + row.versionId + '\',\'' + row.stepId + '\',\'' + row.docId + '\',\'' + row.isMust + '\')"></i> ';
        }
    }

    /* 影像资料必传状态变更 */
    function isMustChange(versionId, stepId, docId, isMust) {
        var msg = "";
        if (isMust == "F") {
            msg = "确认要启用必传状态吗？";
            isMust = "T";
        } else if (isMust == "T") {
            msg = "确认要停用必传状态吗？";
            isMust = "F";
        }
        $.modal.confirm(msg, function () {
            $.operate.post(ctx + "workflow/stepDoc/edit", {
                "versionId": versionId,
                "stepId": stepId,
                "docId": docId,
                "isMust": isMust
            });
        })
    }
</script>
</body>
</html>
